var evalNumberId = getParameter("evalNumberId");
var uid = getParameter("uid");
var maxd=0;
$(function() {
	rt();
});

function rt(){
	var urlStr = serverPath + "/app/doctor/doctor/assess.do";
	var jsonStr = '{method:"dMReport",requestlist:[{evalNumberId:"'+evalNumberId+'"}],  version:"1.0",uid:"'+uid+'", requestsource:"doctor"}' ;
	
	UseAjax(urlStr, jsonStr, document.cookie, tangniaobing, '1');
	}


function tangniaobing(nodeArrays) {
	var nodeArray=nodeArrays.resultlist[0];
	if (nodeArray && nodeArray.hypertensionreport && nodeArray.knowledgebaseresult) {
		var wi = nodeArray.hypertensionreport;
		var kb = nodeArray.knowledgebaseresult;
		var strData = parseFloat(wi.whr) * 100;
		strData = Math.round(strData);
		strData /= 100.00;
		wi.whr = strData.toString();
		if (wi.ishaddisease > 0) {
			wi.ishaddisease = '<font color="red">有</font>';
		} else {
			wi.ishaddisease = "无";
		}

		$("#futureRisk").show();
		
		if (wi.pagecontent == 0) {
			if (wi.hypertensionlevel) {
				$('#chart_title').html(wi.hypertensionlevel);
			} else {
				$('#chart_title').hide();
			}
			$('#chart_content').hide();

			var text = '';
			text = tangniaobingText(text, wi);
			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + '已患糖尿病；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + '</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';
			$('#reportContent').html(text);
		} else if (wi.pagecontent == 1) {
			if (wi.hypertensionlevel) {
				$('#chart_title').html(wi.hypertensionlevel);
			} else {
				$('#chart_title').hide();
			}
			$('#chart_content').hide();

			var text = '';
			text = tangniaobingText(text, wi);
			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + '疑似糖尿病；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + '</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';
			$('#reportContent').html(text);
		} else if (wi.pagecontent == 3) {
			if (wi.hypertensionlevel) {
				$('#chart_title').html(wi.hypertensionlevel);
			} else {
				$('#chart_title').hide();
			}
			$('#chart_content').hide();

			var text = '';
			text = tangniaobingText(text, wi);
			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + '糖调节受损；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + '</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';
			$('#reportContent').html(text);
		} else if (wi.pagecontent == 2) {
			$('#chart_title').html('您未来10年糖尿病的发病风险为：<font color="red">' + wi.hypertensionlevel + '</font>');
			var hylevel = wi.hypertensionlevel;
			var standardLevel = wi.standardlevel;
			var sbgcolor = "";
			if (standardLevel == "高风险") {
				sbgcolor = "#92d050";
			} else if (standardLevel == "极高风险") {
				sbgcolor = "#ff0000";
			} else if (standardLevel == "中等风险") {
				sbgcolor = "#9bbb59";
			} else if (standardLevel == "低风险") {
				sbgcolor = "#8064a2";
			} else if (standardLevel == "极低风险") {
				sbgcolor = "#4bacc6";
			}
			var bgcolor = "";
			if (hylevel == "高风险") {
				bgcolor = "#92d050";
			} else if (hylevel == "极高风险") {
				bgcolor = "#ff0000";
			} else if (hylevel == "中等风险") {
				bgcolor = "#9bbb59";
			} else if (hylevel == "低风险") {
				bgcolor = "#8064a2";
			} else if (hylevel == "极低风险") {
				bgcolor = "#4bacc6";
			}
			d1 = wi.attack ;
			d2 = wi.standardattack;
			if(d1>d2){
				maxd=d1;
			} else {
				maxd=d2;
			}
			var colors = Highcharts.getOptions().colors,
			categories = [ '您的当前风险', '您的理想风险' ], name = '糖尿病评估结果',
			
			data = [
					{
						y : d1,
						color : "#fb0800",
						drilldown : {
							name : 'MSIE versions',
							categories : [ 'MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0',
									'MSIE 9.0' ],
							data : [ 10.85, 7.35, 33.06, 2.81 ],
							color : colors[0]

						}
					},
					{
						y : d2,
						color : "#42b1cf",
						drilldown : {
							name : 'Firefox versions',
							categories : [ 'Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5',
									'Firefox 3.6', 'Firefox 4.0' ],
							data : [ 0.20, 0.83, 1.58, 13.12, 5.43 ],
							color : colors[1]
						}
					} ];

			function setChart(name, categories, data, color) {
				chart.xAxis[0].setCategories(categories, false);
				chart.series[0].remove(false);
				chart.addSeries({
					name : name,
					data : data,
					title : title,
					color : color || 'white'
				}, false);
				chart.redraw();
			}

			var chart = $('#container')
					.highcharts(
							{
								chart : {
									type : 'column'
								},
								title : {
									text : '糖尿病风险评估图',

									style : {
										fontWeight : 'bold',
										color : 'red',
										fontSize : '18px'
									}
								},

								xAxis : {
									categories : categories,
									style : {
										color : 'red'
									}
								},

								yAxis : {
									title : {
										text : '风险值',
										style : {
											color : '#000000',
											fontWeight : 'bold'
										}
									},
									max : maxd*1.2,
									min : 0,
									tickPixelInterval : 40,
									//gridLineColor : 'red',
									tickmarkPlacement : 'between',
									tickColor : '#c0d0e0',
									tickWidth : 0,
									plotlines : 'dashed',
									gridLineWidth : 1,

								},
								plotOptions : {
									column : {
										cursor : 'pointer',
										dataLabels : {
											enabled : true,
											color : colors[0],
											style : {
												fontWeight : 'bold'
											},
											formatter : function() {
											//	return "a";
											}
										}
									}
								},

								series : [ {
									 events: {
			                                //控制图标的图例legend不允许切换
			                               legendItemClick: function (event){                                    
			                                return false; //return  true 则表示允许切换
			                                }
			                            },
									name : name,
									data : data,
									color : 'red'
								} ],
								exporting : {
									enabled : true
								},

							}).highcharts(); // return chart
			
			var text = '';
			text = text + tangniaobingText(text, wi);
			text = text + '<h2>风险提示：</h2>';
			text = text + '<ul>';
			text = text + '<li>' + kb.knowledgeBase1 + wi.hypertensionlevel + '；</li>';
			text = text + '<li>' + kb.knowledgeBase2 + wi.standardlevel + '；</li>';
			text = text + '<li>' + kb.knowledgeBase3 + wi.risks + '；</li>';
			text = text + '<li>' + kb.knowledgeBase4 + '</li>';
			text = text + '</ul>';

			$('#reportContent').html(text);
		}
	} else {
		$('#chart_content').hide();
		$('#chart_title').hide();
		$('#reportContent').html(
			'<div><span style="font-size:16px;"><span style="color: rgb(105, 105, 105); "><span style="font-family: 黑体; ">没有记录</span></span></span></div>'
		);
	}
	
}
function tangniaobingText(text, wi) {
	text = text + '<h2>危险因素列表:</h2>';
    text = text + '<table class="risk-list">';
    text = text + '<tr><th class="th1">危险因素</th><th class="th2">您的情况</td><th class="th3 ">参考值</th></tr>';
    text = text + '<tr><td>年龄</td><td>' + wi.age + '</td><td>随年龄增长风险增高</td></tr>';
    if (wi.fdisease == 1) {
    	text = text + '<tr class="high-light"><td>糖尿病家族史</td><td>有</td><td>无</td></tr>';
    } else {
    	text = text + '<tr><td>糖尿病家族史</td><td>无</td><td>无</td></tr>';
    }
    if (wi.chd > 0) {
    	text = text + '<tr class="high-light"><td>冠心病疾病史</td><td>有</td><td>无</td></tr>';
    } else {
    	text = text + '<tr><td>冠心病疾病史</td><td>无</td><td>无</td></tr>';
    }
    if (wi.hypertension > 0) {
    	text = text + '<tr class="high-light"><td>高血压疾病史</td><td>有</td><td>无</td></tr>';
    } else {
    	text = text + '<tr><td>高血压疾病史</td><td>无</td><td>无</td></tr>';
    }
	if (parseFloat(wi.bmi) < 18.5 || parseFloat(wi.bmi) >= 24) {
		text = text + '<tr class="high-light"><td>BMI</td><td>' + wi.bmi + '</td><td>18.5&le;BMI&lt;24</td></tr>';
	} else {
		text = text + '<tr><td>BMI</td><td>' + wi.bmi + '</td></td><td>18.5&le;BMI&lt;24</td></tr>';
	}
	if (parseFloat(wi.systolic) >= 120) {
		text = text + '<tr class="high-light"><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
	} else {
		text = text + '<tr><td>血压（收缩压）</td><td>' + wi.systolic + '</td><td><120mmHg</td></tr>';
	}
	if (parseFloat(wi.diastolic) >= 80) {
		text = text + '<tr class="high-light"><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
	} else {
		text = text + '<tr><td>血压（舒张压）</td><td>' + wi.diastolic + '</td><td><80mmHg</td></tr>';
	}
	if ((wi.sex == 0 && parseFloat(wi.whr) >= 0.9) || (wi.sex == 1 && parseFloat(wi.whr) >= 0.85)) {
		text = text + '<tr class="high-light"><td>腰臀围比</td><td>' + wi.whr + '</td><td><0.85（女）<0.9(男)</td></tr>';
	} else {
		text = text + '<tr><td>腰臀围比</td><td>' + wi.whr + '</td><td><0.85（女）<0.9（男）</td></tr>';
	}
	if (wi.pulse >= 90) {
		text = text + '<tr class="high-light"><td>脉搏</td><td>' + wi.pulse + '</td><td><90</td></tr>';
	} else {
		text = text + '<tr><td>脉搏</td><td>' + wi.pulse + '</td><td><90</td></tr>';
	}
    if (wi.polyuria > 0) {
    	text = text + '<tr class="high-light"><td>多饮多尿</td><td>有</td><td>无</td></tr>';
    } else {
    	text = text + '<tr><td>多饮多尿</td><td>无</td><td>无</td></tr>';
    }
    if (wi.ulcer > 0) {
    	text = text + '<tr class="high-light"><td>肢端溃疡</td><td>有</td><td>无</td></tr>';
    } else {
    	text = text + '<tr><td>肢端溃疡</td><td>无</td><td>无</td></tr>';
    }
	
	text = text + '</table>';

	return text;
}

// 获取url参数
function getParameter(param) {
	var query = window.location.search;
	var iLen = param.length;
	var iStart = query.indexOf(param);
	if (iStart == -1)
		return "";
	iStart += iLen + 1;
	var iEnd = query.indexOf("&", iStart);
	if (iEnd == -1)
		return query.substring(iStart);
	return query.substring(iStart, iEnd);
}